refactor: code block & math block syntax highlighting#2873
Conversation
Logged-out buyers now go straight to Polar checkout instead of being sent to /signup first.
De-duplication: when an extension with a given key is already registered, skip registering another one with the same key (the first registration wins). This lets an extension declare a dependency on another via `blockNoteExtensions` without conflicting when that same extension is also registered directly by the user. Ordering: a sub-extension declared via `blockNoteExtensions` is a dependency of the extension that declares it, so it now runs before its parent. The dependency is recorded as the sub is resolved (before the de-duplication check), so it holds even when multiple parents declare the same sub-extension and when a parent has a higher base priority via `runsBefore`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… & math block can configure a highlighter for
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Looks good, I agree that trying to merge duplicate extensions is probably more effort than what we need atm and better to drop them.
Though I'm not a bit wary of keeping the highlighting option in meta when there is a specific extension for it. I think we should be careful when adding things to the custom block API that we don't end up with like a dozen unrelated config options that all live under meta. Probably fine in this case but yeah it's something we should be careful with. I guess an alternative would be to not bundle the syntax highlight extension with the code or math blocks, and make it completely standalone + configure highlighting there.
|
My thinking there is that it is inflexible (and annoying) to have a shared dep have to be aware of the details of each block and it's special cases. I would rather that the blocks could declare how they should be treated by an extension instead of the extension having to be aware of the block. The reason is two fold:
A perfect example of this is the slash menu. Right now, we have the default blocks automatically injected into the shared slash menu array. When, if we did it in this way, we'd have each block declaring what sort of block it is and how to show itself in the slash menu. So, the slash menu would be simpler and including new things into the slash menu would be easier. Rather than having to modify the shared state somewhere else. |
Summary
The goal of this refactor was to use #2872 which allows for "sub extensions" (a blocknote extension within a blocknote extension) to be de-duped. And, leverage that to allow both the code-block & math block to operate with the syntax highlighting extension.
Now, the math block & code block declares how to highlight their contents & the syntax highlighting extension will pickup on them as being the nodes they should try to syntax highlight upon.
I've made the code block accept the syntax highlighter like it was accepting before. And, now the math block can accept a syntax highlighter (if for some reason you only care to configure the math block highlighting but not the code block one).
The trouble is how to handle both code block & the math extension wanting to configure the highlighter in different ways. Well, extensions can now only be registered once per key with #2872 so it will just silently drop one of the configurations and use one of the highlight instances to try to highlight both the math & code blocks.
I think this is a fine tradeoff for now, since you can really just leave the code block syntax highlighting on & get both code blocks & math blocks "for free". There is a larger question on how to do this in the more general case for extensions which depend on each other, but that is just a hard problem in programming in general.
Rationale
Changes
Impact
Testing
Screenshots/Video
Checklist
Additional Notes